package com.dinadi.yidi.ui.fragment;

import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.dinadi.yidi.R;
import com.dinadi.yidi.base.BaseFragment;
import com.dinadi.yidi.utils.SharePreferencesHelper;

/**
 * author: JiaYu.He
 * Date: 2017/4/19   设计师详情-文章
 * Time: 17:18
 */

public class DesignerArticleFragment extends BaseFragment {
    private View view;
    private WebView activity_web;

    @Override
    protected void noWifiRefresh() {

    }

    @Override
    protected View getLayout() {
        view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_designer_article, null);
        return view;
    }

    @Override
    protected void initView() {
        changePager(2);
        activity_web = (WebView) view.findViewById(R.id.activity_web);
//        //支持javascript
//        activity_web.getSettings().setJavaScriptEnabled(true);
//        // 设置可以支持缩放 
//        activity_web.getSettings().setSupportZoom(true);
//        // 设置出现缩放工具 
//        activity_web.getSettings().setBuiltInZoomControls(true);
//        //扩大比例的缩放
//        activity_web.getSettings().setUseWideViewPort(true);
//        //自适应屏幕
//        activity_web.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
//        activity_web.getSettings().setLoadWithOverviewMode(true);

        // 支持缩放(适配到当前屏幕)  
        WebSettings webSettings = activity_web.getSettings();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {//少于4.4（不包括4.4）用这个  
            webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        }
        //适应屏幕，大于等于4.4用这个  
        webSettings.setUseWideViewPort(true);
        webSettings.setSupportZoom(true);
        webSettings.setLoadWithOverviewMode(true);


        // 覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开
        activity_web.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // 返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });
    }



    @Override
    protected void initListener() {

    }

    @Override
    protected void clickEvent(View v) {

    }

    @Override
    protected void initData() {

          String htmlPath = SharePreferencesHelper.getInstance(getActivity()).getString("htmlPath");
        activity_web.loadUrl(htmlPath);
    }

}
